package pers.kw.server.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import pers.kw.crm.api.UserApi;
import pers.kw.crm.dto.UserDto;
import pers.kw.entity.PageDto;
import pers.kw.feign.FileApiService;
import pers.kw.file.dto.FileDto;
import pers.kw.protocol.R;
import pers.kw.server.user.dto.QueryUserReqDto;
import pers.kw.server.user.service.UserService;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "crm用户服务")
@RestController
public class UserController implements UserApi {
    @Resource
    private FileApiService fileApiService;

    @Resource
    private UserService userService;

    @ApiOperation(value = "新增用户")
    @PutMapping(value = "/crm/api/user/add")
    public R<String> addUser(@Valid @RequestBody UserDto reqDto) {
        return R.ok(userService.addUserUseLock(reqDto));
    }

    @ApiOperation(value = "获取用户头像图片")
    @GetMapping(value = "/crm/api/user/get/picture")
    public R<FileDto> getUserPicture() {
        //return fileApiService.getFileByFileToken();
        return null;
    }

    @ApiOperation(value = "分页查询用户列表")
    @PostMapping(value = "/crm/api/user/page")
    public R<PageDto<UserDto>> pageQueryUserList(@Valid @RequestBody QueryUserReqDto reqDto) {
        return R.ok(userService.pageQueryUserList(reqDto));
    }

    @Override
    public R<UserDto> getUserInfo(String userNo) {
        return R.ok(userService.getUserByUserNo(userNo));
    }

    @ApiOperation(value = "通过登录信息获取userInfo")
    @GetMapping(value = "/crm/api/user/info")
    public R<UserDto> getUserInfo() {
        return R.ok(userService.getUserInfo());
    }
}
